/*
 * GeoVISTA Center (Penn State, Dept. of Geography)
 * Copyright (c), 2003-2011,  Jin Chen and Alan M. MacEachren, GeoVISTA Center, Penn State University
 * Licensed under Simplified BSD License
 *
 *  
 * @author: jin Chen 
 * @date: Nov 17, 2005$
 * @version: 1.0
 */
package edu.psu.geovista.app.gmatrix.canvas;

import edu.psu.geovista.app.gmatrix.data.BasicMatrixmodel;

import java.awt.*;

public class DfCell implements Cell {

    //intrinsic attributes
    private Point index; //(x,y)
    private Symbol symbol;// 



    //extrinsic attributes
    private Color foreground ;
    private boolean style3d;
    private Rectangle symbolBoundary;// 
    private Color background;
    private Rectangle bounds; //todo need store this? 

    BasicMatrixmodel datamodel;
    /**
     * It is recommend to use DfCell(Symbol symbol) so that u can set a single object of symbol
     */
    public DfCell() {
        index=new Point();
        setSymbol(new RectangleSymbol());//default symbol
    }

    public DfCell(Symbol symbol) {
        this.setSymbol(symbol);
        index=new Point();
    }
    public void paint(Graphics g){
        Color background =this.getBackground() ;
        Rectangle bd = this.getBounds();

        g.setColor(background);
//          System.out.println("paint cell["+index.x+","+index.y+"] size("+bd.width +","+bd.height +") at ["+bd.x+","+bd.y+"] in color"+background.toString() );
        g.fillRect(bd.x,bd.y,bd.width ,bd.height );

        getSymbol().paint(g, this);
    }
    /*public void paint(Graphics g,CellContext context){
        Point index = this.getIndex();
        int row = index.x;
        int col = index.y;
        Color background = context.getBackground(row,col);
        Color foreground = context.getForeground(row,col);
        boolean style3d = context.isStyle3d();
//        System.out.println(this.index.toString() +" color "+background.toString());

        //draw a cell
         g.setColor(background);
         Rectangle bd = context.computeCellBound(row,col);

        g.fillRect(bd.x,bd.y,bd.width ,bd.height );
        Rectangle symbolbound = context.computeSymbolBoundary(row, col);
       // System.out.println(row+", "+col+" size "+symbolbound);
        symbol.paint(g, null);

     }*/
    /*******************************************************************************************************
     *                intrinsic attributes, always carry
     *******************************************************************************************************/
    public Point getIndex() {
        return index;
    }

    public void setIndex(int x, int y) {
        this.index.setLocation(x,y);
    }

    public Symbol getSymbol() {
        if(symbol==null&&datamodel!=null){
            return datamodel.getDefaultSymbol();
        }
        return symbol;
    }

    public void setSymbol(Symbol symbol) {
        this.symbol = symbol;
    }

    /*******************************************************************************************************
     *                extrinsic attributes, just carry this attribute and pass to other component
     *******************************************************************************************************/
    public Color getBackground() {
         if(background==null&&datamodel!=null){
            return datamodel.getDefaultBackground();
        }
        return background;
    }

    public void setBackground(Color background) {

        this.background = background;
    }

    public Color getForeground() {
        if(foreground==null&&datamodel!=null){
            return datamodel.getDefaultForeground();
        }
        return foreground;
    }

    public void setForeground(Color foreground) {
        this.foreground = foreground;
    }

    public boolean isStyle3d() {
        return style3d;
    }

    public void setStyle3d(boolean style3d) {
        this.style3d = style3d;
    }
    public Rectangle getSymbolBoundary() {
       
        return symbolBoundary;
    }

    public void setSymbolBoundary(Rectangle symbolBoundary) {
        this.symbolBoundary = symbolBoundary;
    }
    public Rectangle getBounds() {
        return bounds;
    }

    public void setBounds(Rectangle boundary) {
        this.bounds = boundary;
    }

    public void setDatamodel(BasicMatrixmodel datamodel) {
        this.datamodel = datamodel;
    }
}

   //private float symbolSizeRatio =1;// 

 /* public Point getSymbolCenter(){
        return symbol.getSymbolCenter(this);


    }*/

   /* public Rectangle getBoundary() {
        return boundary;
    }

    public void setBoundary(Rectangle boundary) {
        this.boundary = boundary;
    }

    public Color getBackground() {
        return background;
    }

    public void setBackground(Color background) {
        this.background = background;
    }

    public Color getForeground() {
        return foreground;
    }

    public void setForeground(Color foreground) {
        this.foreground = foreground;
    }*/

    /*  public float getSymbolSizeRatio() {
        return symbolSizeRatio;
    }

    public void setSymbolSizeRatio(float symbolSizeRatio) {
        if(symbolSizeRatio <0||symbolSizeRatio >1){
           new IllegalArgumentException(this.getClass().getName() +" only accept a value between 0-1 ");
        }
        this.symbolSizeRatio = symbolSizeRatio;
    }*/
/*
    public boolean isSelectMode() {
        return selectMode;
    }

    public void setSelectMode(boolean selectMode) {
        this.selectMode = selectMode;
    }

    public boolean isStyle3d() {
        return style3d;
    }

    public void setStyle3d(boolean style3d) {
        this.style3d = style3d;
    }

    public boolean isHighlightMode() {
        return highlightMode;
    }

    public void setHighlightMode(boolean highlightMode) {
        this.highlightMode = highlightMode;
    }*/
 // private Color background=Color.BLACK;
    //private Color foreground;// 
       //private Rectangle boundary; // the size and location of the boundary of the cell where the symbol reside

   // boolean style3d=false;
    //boolean selectMode=false;
    //boolean highlightMode =false;